package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import com.sky.vo.TurnoverReportVO;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.PostMapping;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrdersMapper {
    /**
     * 添加订单表
     *
     * @param orders
     */
    @Options(keyProperty = "id", useGeneratedKeys = true)
    @Insert("insert into sky_take_out.orders values (null,#{number},#{status},#{userId},#{addressBookId},#{orderTime}" +
            ",#{checkoutTime},#{payMethod},#{payStatus},#{amount},#{remark},#{phone},#{address},#{userName},#{consignee},#{cancelReason},#{rejectionReason},#{cancelTime},#{estimatedDeliveryTime}" +
            ",#{deliveryStatus},#{deliveryTime},#{packAmount},#{tablewareNumber},#{tablewareStatus})")
    void add(Orders orders);

    /**
     * 分页查询订单
     *
     * @param dto
     * @return
     */
    Page<OrderVO> ordersPage(OrdersPageQueryDTO dto);

    /**
     * 根据id查询订单
     *
     * @param id
     * @return
     */
    @Select("select * from sky_take_out.orders where id = #{id}")
    OrderVO findById(Long id);

    /**
     * 修改订单状态
     *
     * @param orders
     */
    //@Update("update sky_take_out.orders set status=#{status} where id=#{id}")
    void updateOrder(Orders orders);

    /**
     * 根据起售状态查询订单总数
     *
     * @return
     */
    @Select("select count(*) from sky_take_out.orders where status=#{status}")
    Integer statistics(Integer status);

    /**
     * 根据起售状态和下单时间查询订单
     * @param status
     * @param orderTime
     * @return
     */
    @Select("select * from sky_take_out.orders where status=#{status} and order_time >#{orderTime}")
    List<Orders> getByStatusAndOrderTimeLT(Integer status, LocalDateTime orderTime);

    /**
     * 统计销量排名前10的菜品
     * @param map
     * @return
     */
    List<GoodsSalesDTO> top10(Map<String, Object> map);

    /**
     * 营业额统计
     * @param map
     * @return
     */
    Double turnoverStatistics(Map<String, Object> map);

    /**
     * 订单统计
     * @param map
     * @return
     */
    Integer ordersStatistics(Map<String, Object> map);
}
